<template>
  <div>
    <el-card>
      <el-row :gutter="20">
        <el-col :span="6">
          所属类型:
          <el-select v-model="queryInfo.type" placeholder="请选择" style="width: 73%" size="mini" @change="loadData()">
            <el-option v-for="item in menulist" :key="item.id" :label="item.authName" :value="item.id"> </el-option>
          </el-select>
        </el-col>
        <el-col :span="4">
          样本编号:
          <el-input style="width: 100px" size="mini" v-model="queryInfo.number"></el-input>
        </el-col>
        <el-col :span="4">
          样本牌号:
          <el-input style="width: 100px" size="mini" v-model="queryInfo.mark"></el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" size="mini" @click="queryData">查询</el-button>
        </el-col>
      </el-row>
      <el-row style="margin: 10px 0 10px">
        <el-col :span="2">
          <el-button type="primary" size="mini" @click="addParameterVisible = true"><i class="el-icon-plus"></i>添加</el-button>
        </el-col>
        <el-col :span="2" style="margin-left: 10px">
          <el-button type="primary" size="mini" @click="showImport"><i class="el-icon-arrow-right"></i>导入</el-button>
        </el-col>
      </el-row>
      <el-table :data="parameterList" border height="500px" style="margin: 10px 0 10px">
        <el-table-column align="center" type="index"></el-table-column>
        <el-table-column align="center" label="样本编号" prop="datatype"></el-table-column>
        <el-table-column align="center" label="牌号" prop="number"></el-table-column>
        <el-table-column align="center" label="样品规格" prop="mark"></el-table-column>
        <el-table-column align="center" label="文件名" prop="supplier"></el-table-column>
        <el-table-column align="center" label="频率/Hz" prop="supplier" width="110"></el-table-column>
        <el-table-column align="center" label="温度/Cel.Deg." prop="supplier"></el-table-column>
        <el-table-column align="center" label="测量人员	" prop="people"></el-table-column>
        <el-table-column align="center" label="测量数据">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-s-tools" @click="showMData(scope.row)"> </el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-edit" @click="showeditDia(scope.row)"> </el-button>
            <el-button type="text" icon="el-icon-delete" @click="showDel(scope.row, 1)"> </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryInfo.pagenum" :page-sizes="[100, 200, 400, 800]" :page-size="queryInfo.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
    </el-card>

    <!-- 添加和编辑测量条件信息 -->
    <el-dialog title="编辑测量条件信息" :visible.sync="addParameterVisible" width="60%">
      <el-form :inline="true">
        <el-form-item label="样品编号:" label-width="170px">
          <el-select v-model="parameter.productId" placeholder="请选择" style="width: 191px">
            <el-option v-for="item in productIdList" :key="item.id" :label="item.id" :value="item.id"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属类型:" label-width="170px">
          <el-select v-model="parameter.type" placeholder="请选择" style="width: 191px">
            <el-option v-for="item in menulist" :key="item.id" :label="item.authName" :value="item.id"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="裁剪角度/Deg.:" label-width="170px">
          <el-input v-model="parameter.cuttingAngle"></el-input>
        </el-form-item>
        <el-form-item label="测量间距/m:" label-width="170px">
          <el-input v-model="parameter.measuringDistance"></el-input>
        </el-form-item>
        <el-form-item label="频率/Hz:" label-width="170px">
          <el-input v-model="parameter.frequency"></el-input>
        </el-form-item>
        <el-form-item label="温度/Cel.Deg.:" label-width="170px">
          <el-input v-model="parameter.temperature"></el-input>
        </el-form-item>
        <el-form-item label="应力/MPa:" label-width="170px">
          <el-input v-model="parameter.stress"></el-input>
        </el-form-item>
        <el-form-item label="消除应力退火:" label-width="170px">
          <el-input v-model="parameter.stressReliefAnnealing"></el-input>
        </el-form-item>
        <el-form-item label="测量标准:" label-width="170px">
          <el-input v-model="parameter.standard"></el-input>
        </el-form-item>
        <el-form-item label="测试员:" label-width="170px">
          <el-input v-model="parameter.testControler"></el-input>
        </el-form-item>
        <el-form-item label="文件名:" label-width="170px">
          <el-input v-model="parameter.fileName"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addParameterVisible = false">取 消</el-button>
        <el-button type="primary" @click="addParameter">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 测量数据对话框 -->
    <el-dialog title="添加测量数据信息" :visible.sync="mdataDiaVisible" width="60%">
      <el-button type="primary" @click="addMData">新增</el-button>
      <el-table :data="mdataList">
        <el-table-column type="index"></el-table-column>
        <el-table-column align="center" label="J/(A/m^2)" prop="J1"></el-table-column>
        <el-table-column align="center" label="Rou/(ohm.m)" prop="rou"></el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-edit" @click="showedit(scope.row)"> </el-button>
            <el-button type="text" icon="el-icon-delete" @click="showDel(scope.row, 2)"> </el-button>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="mdataDiaVisible = false">取 消</el-button>
        <el-button type="primary" @click="mdataDiaVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 修改和新增测量数据对话框 -->
    <el-dialog title="修改测量数据" :visible.sync="editMDataDiaVisible" width="50%">
      <el-from>
        <el-form-item label="J/(A/m^2):" label-width="170px">
          <el-input v-model="editmdataList.J1"></el-input>
        </el-form-item>
        <el-form-item label="Rou/(ohm.m):" label-width="170px">
          <el-input v-model="editmdataList.rou"></el-input>
        </el-form-item>
      </el-from>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editMDataDiaVisible = false">取 消</el-button>
        <el-button type="primary" @click="editMDataDiaVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 删除提示对话框 -->
    <el-dialog title="提示" :visible.sync="delDiaVisible" width="50%">
      <span style="font-size: 20px; display: inline-block; align: center">确定删除此数据吗？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="delDiaVisible = false">取 消</el-button>
        <el-button type="primary" @click="del()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 导入按钮 -->
    <el-dialog title="提示" :visible.sync="importTag" width="60%">
      <div style="font-size: 20px; margin-left: 40px">请下载导入模板进行导入</div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" style="margin-right: 20px" @click="exportData">下载模板</el-button>
        <a-upload name="file" :action="uploadUrl" accept=".xls,.xlsx" :data="paramData" :multiple="true" @change="handleChange" :showUploadList="false">
          <el-button type="primary">已有模板，立即导入</el-button>
        </a-upload>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      importTag: false,
      paramData: {
        name: '2'
      },
      uploadUrl: 'http://59.172.104.174:30669/admin/uploadLessonFile',
      //所属类型下拉
      menulist: [
        {
          id: '导电静态电阻曲线',
          authName: '导电性能+静态+电阻曲线'
        },
        {
          id: '导电静态电阻率曲线',
          authName: '导电性能+静态+电阻率曲线'
        },
        {
          id: '导电静态伏安曲线',
          authName: '导电性能+静态+伏安曲线'
        },
        {
          id: '导电静态电导率曲线',
          authName: '导电性能+静态+电导率曲线'
        }
      ],
      editmdataList: {
        J1: '',
        rou: ''
      },
      addmdataList: {
        J1: '',
        rou: ''
      },
      total: 0,
      mdataList: [
        { J1: '22', rou: '33' },
        { J1: '22', rou: '33' }
      ], //测量数据
      delItemId: '',
      editMDataDiaVisible: false, //控制修改和新增测量数据对话框
      mdataDiaVisible: false, //控制点击测量条件对话框
      delDiaVisible: false,
      //添加样本
      parameter: {
        id: '',
        type: '', //给曲线类型
        productId: '',
        cuttingAngle: '',
        measuringDistance: '',
        frequency: '',
        temperature: '',
        stress: 'String',
        stressReliefAnnealing: '',
        standard: '',
        testControler: '',
        fileName: ''
      },
      addParameterVisible: false,
      selectParameterVisible: false,
      parameterList: [
        //   {
        //   datatype: '22',
        //   number: '33',
        //   mark: '44',
        //   home: '55',
        //   supplier: '66',
        //   timeIn: '77',
        //   people: '陈志华'
        // }, {
        //   datatype: '22',
        //   number: '33',
        //   mark: '44',
        //   home: '55',
        //   supplier: '66',
        //   timeIn: '77',
        //   people: '陈志华'
        // }
      ],
      typeList: [
        {
          name: '导电性能+静态+电阻曲线',
          id: 1
        },
        {
          name: '导电性能+静态+电阻率曲线',
          id: 2
        },
        {
          name: '导电性能+静态+伏安曲线',
          id: 3
        },
        {
          name: '导电性能+静态+电导率曲线',
          id: 4
        }
      ],
      queryInfo: {
        // number: '',
        // mark: '',
        // supplier: '',
        pageNum: 1,
        pageSize: 10,
        type: '导电静态电阻曲线'
      },
      productIdList: [],
      delType: 0,
      delName: ''
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    addMData() {},
    handleChange(info) {
      if (info.file.status === 'done') {
        if (info.file.response.code == '201') {
          this.$message.success('重新上传文件成功！')
        } else if (info.file.response.code == '200') {
          this.$message.success('上传文件成功！')
        }
      }
    },
    //模板导出按钮
    exportData() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/admin/downLoadLessonFile?name=牌号标签`,
        methods: 'GET',
        responseType: 'blob'
      }).then(res => {
        const blob = new Blob([res.data])
        const url = window.URL.createObjectURL(blob)
        const link = document.createElement('a')
        link.style.display = 'none'
        link.download = `牌号标签.xlsx`
        link.href = url
        link.click()
      })
    },
    showImport() {
      this.importTag = true
    },
    queryData() {},
    showMData(row) {
      this.mdataDiaVisible = true
      // })
    },
    showeditDia(row) {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/eleMeasurement/selectMeasurementById?id=${row.id}&type=${this.queryInfo.type}`,
        method: 'GET'
      }).then(res => {
        this.parameter = res.data.result
        this.addParameterVisible = true
      })
    },
    addmdata() {},
    selectParameter() {
      this.addParamseterVisible = true
    },
    addParameter() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: '/eleMeasurement/insertOrUpdate',
        method: 'POST',
        data: this.parameter
      }).then(res => {
        if (res.data.code == 200) {
          this.$message.success('操作成功！！！')
          this.addParameterVisible = false
        }
      })
    },
    //控制删除对话框
    showDel(row, flag) {
      this.delItemId = row.id
      this.delDiaVisible = true
      this.delType = flag
    },
    //发起真正的删除操作
    del() {
      if ((this.delType = 2)) {
      } else if ((this.delType = 1)) {
        //删一行
        this.axios({
          baseURL: 'http://59.172.104.174:30669',
          url: `/eleMeasurement/deleteMeasurement?id=${this.delItemId}&type=${this.queryInfo.type}`,
          methods: 'GET'
        }).then(res => {
          if (res.data.code == 200) {
            this.$message.success('删除成功')
            this.loadData()
            this.delDiaVisible = false
          }
        })
      }
    },
    //分页控制
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pageNum = newPage
    },
    getAllProductId() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: '/perMagnetParameter/selectParameter',
        method: 'POST',
        data: {
          pageNum: 1,
          pageSize: 10
        }
      }).then(res => {
        this.productIdList = res.data.result.records.map(x => {
          return new Object({ id: x.id })
        })
        console.log(this.productIdList)
      })
    },
    loadData() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/eleMeasurement/selectMeasurement`,
        method: 'POST',
        data: this.queryInfo
      }).then(res => {
        //this.getAllProductId()
        this.parameterList = res.data.result.records
      })
    }
  }
}
</script>

<style scoped></style>
